jQuery(document).ready(function($) {
	getArticleSort();
	   
});

//删除文章分组 
function delArticleSrot(){
	var delArticleSortURL = $('#delArticleSrot').attr('artilesortid');
	$.post(delArticleSortURL, function(data, textStatus, xhr) {
		/*optional stuff to do after success */
	});
	 $('.artilesort').html('');
	 getArticleSort();

}

//添加文章分组
function addArticleSort(){
	 var sort_article_name = $('#articleSortName').val();
	 var addArticleSortURL=getContextPath()+"/backStage/addarticlesort"
	 $.post(addArticleSortURL, {"sort_article_name": sort_article_name}, function(data, textStatus, xhr) {
	 	/*optional stuff to do after success */
	 });

	  $('.artilesort').html('');
	 getArticleSort();
	
}


//获取文章分组
function getArticleSort(){
		var articlesortURL=getContextPath()+"/backStage/getarticlesort";

		/*optional stuff to do after success 
	"<div class='row'><div class='col-50'><a href='#' class='button button-big button-fill'>"+articlesort.sort_article_name+"</a></div><div class='col-50'><a href='#' class='button button-big button-fill button-danger'>删除</a></div></div>"

	*/
	$.ajax({
		url: articlesortURL,
		type: 'POSt',
		dataType: 'json'
	})
	.done(function(data) {
		console.log(data);

			var tempHTML="";
			for (var i = 0; i < data.length; i++) {
		var articlesort =data[i];
			var delArticleSortURL = getContextPath() + "/backStage/delarticlesort?sortArticleId=" + articlesort.sortArticleId;
		tempHTML+="<div class='row'><div class='col-50'><a href='javascript:;' id='article' artilesortid='"+articlesort.sortArticleId+"' class='button button-big button-fill' >"+articlesort.sort_article_name+"</a></div><div class='col-50'><a href='javascript:;' class='button button-big button-fill button-danger' id='delArticleSrot' onclick='delArticleSrot()' artilesortid='"+delArticleSortURL+"'>删除</a></div></div>"

		
	} //for结束

	$('.artilesort').html(tempHTML);




	})
	.fail(function() {
		console.log("error");
	})
	.always(function() {
		console.log("complete");
	});
}

function getContextPath() { //获取根路径

	var pathName = document.location.pathname;
	var index = pathName.substr(1).indexOf("/");
	var result = pathName.substr(0, index + 1);
	return result;
}